#include <set>
#include "message.h"

Message::Message(const Message &msg):
    contents(msg.contents), folders(msg.folders) {
    put_Msg_in_Folders(folders);
}

void Message::put_Msg_in_Folders(const std::set<Folder*> &rhs) {
    for (std::set<Folder*>::const_iterator iter = rhs.begin();
            iter != rhs.end(); ++iter) {
        (*iter)->addMsg(*this);
    }
}


Message& Message::operator=(const Message &rhs) {
    if (&rhs != this) {
        remove_Msg_from_Folders();
        contents = rhs.contents;
        folders = rhs.folders;
        put_Msg_in_Folders(folders);
    }
    return *this;
}

void Message::remove_Msg_from_Folders() {
    for (std::set<Folder*>::const_iterator iter = folders.begin();
         iter != folders.end(); ++iter) {
        (*iter)->remMsg(*this);
    }
}

Message::~Message() {
    remove_Msg_from_Folders();
}

void Message::save(Folder &folder) {
}

void Message::remove(Folder &folder) {
}
